<template>
  <div class="userCard">
    <div class="userCard-header flexCol mb30">
      <el-tooltip class="item" effect="dark" content="更换头像" placement="bottom">
        <CuploadImageOnce round :external-image-url.sync="userInfo.avatar[0].url" class="userCard-header-uploadImage" @onSuccess="avatarOnSuccess" />
      </el-tooltip>
      <h3 style="line-height: 26px;margin: 0;" class="fs18">{{ userInfo.userName | isNullData }}</h3>
      <p style="line-height: 26px;margin: 0;" class="fs14 labelColor">{{ userInfo.descText | isNullData }}</p>
    </div>
    <div class="userCard-content mb30">
      <el-row :gutter="10">
        <el-col :span="10" class="labelColor">店铺评分：</el-col>
        <el-col :span="14" class="contentColor">
          <el-rate
            v-model="rate"
            disabled
            show-score
            text-color="#ff9900"
            allow-half
            score-template="{value}"
          />
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="10" class="labelColor">联系手机号：</el-col>
        <el-col :span="14" class="contentColor">{{ userInfo.phone | isNullData }}</el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="10" class="labelColor">店铺地址：</el-col>
        <el-col :span="14" class="contentColor">{{ address }}</el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="10" class="labelColor">注册时间：</el-col>
        <el-col :span="14" class="contentColor">{{ userInfo.createTime|setTime }}</el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="10" class="labelColor">最后登陆时间：</el-col>
        <el-col :span="14" class="contentColor">{{ userInfo.lastLoginTime|setTime }}</el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import CuploadImageOnce from '@/components/CuploadImageOnce'
import { mapGetters } from 'vuex'
export default {
  name: 'UserCard',
  components: { CuploadImageOnce },
  computed: {
    ...mapGetters(['userInfo', 'name']),
    // 计算店铺评分
    rate() {
      const rate_count = this.userInfo.rate_count.replace('%', '')
      return Number((rate_count / 25).toFixed(1)) // 25% === element评分组件的1
    },
    // 店铺地址
    address() {
      if (this.userInfo.province) {
        return this.userInfo.province + this.userInfo.city + this.userInfo.county + this.userInfo.addressDetail
      }
      return '未填写'
    }
  },
  methods: {
    // 上传头像成功回调
    async avatarOnSuccess(avatar) {
      const res = await this.$store.dispatch('user/modify', { avatar })
      if (res === 0) {
        this.$message.success('修改成功')
        this.$store.dispatch('user/getInfo')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.labelColor{
  color: #8F8F8F;
}
.contentColor{
  color: #303133;
}
.userCard{
  padding: 10px 20px;
  &-header{
    width: 100%;
    margin-top: 90px;
    padding-bottom: 20px;
    background-color: #fff;
    border-radius: 10px;
    &-uploadImage{
      margin-top: -90px;
      margin-bottom: 20px;
    }
  }
  &-content{
    width: 100%;
    background-color: #fff;
    border-radius: 10px;
    font-size: 14px;
    padding: 10px 20px;
    ::v-deep .el-row{
      line-height: 35px;
    }
  }
}
</style>
